package com.college.controller.resource;


import com.college.common.pojo.ao.CarouselImage;
import com.college.common.pojo.ao.CarouselImage;
import com.college.common.pojo.dto.resource.AddCarouselImageDTO;
import com.college.common.pojo.dto.resource.QueryCarouselImageDTO;
import com.college.common.pojo.dto.resource.UpdateCarouselImageDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonPage;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.resource.mapper.CarouselImageMapper;
import com.college.resource.service.CarouselImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图 前端控制器
 * @author 小C工作室
 * @since 2025-02-22
 */
@RestController
@RequestMapping("/carousel-image")
@Api(tags = "轮播图")
@Slf4j
public class CarouselImageController {

    @Autowired
    private CarouselImageService carouselImageService;

    @ApiOperation(value = "查询轮播图列表")
    @GetMapping(value = "/query-list")
    public CommonResult<List<CarouselImage>> queryList(QueryCarouselImageDTO queryCarouselImageDTO) {
        return CommonResult.success(carouselImageService.queryList(queryCarouselImageDTO));
    }

    @ApiOperation(value = "查询轮播图列表分页")
    @GetMapping(value = "/query-list-page")
    public CommonResult<CommonPage<CarouselImage>> queryListPage(QueryCarouselImageDTO queryCarouselImageDTO , PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(carouselImageService.queryListPage(queryCarouselImageDTO,pageParamRequest)));
    }

    @ApiOperation(value = "新增轮播图")
    @PostMapping(value = "/add")
    public CommonResult<String> addCarouselImage(@RequestBody AddCarouselImageDTO addCarouselImageDTO) {
        return carouselImageService.addCarouselImage(addCarouselImageDTO);
    }

    @ApiOperation(value = "删除轮播图")
    @DeleteMapping(value = "/delete/{id}")
    public CommonResult<Boolean> deleteCarouselImage(@PathVariable Long id) {
        return CommonResult.success(carouselImageService.removeById(id));
    }

    @ApiOperation(value = "批量删除轮播图")
    @DeleteMapping(value = "/batch-delete")
    public CommonResult<Boolean> deleteCarouselImage(@RequestBody List<Long> ids) {
        if (ObjectUtil.isNotEmpty(ids)) {
            return CommonResult.success(carouselImageService.removeByIds(ids));
        }
        return CommonResult.success("参数错误");
    }

    @ApiOperation(value = "更新轮播图")
    @PutMapping(value = "/update")
    public CommonResult<String> updateCarouselImage(@RequestBody UpdateCarouselImageDTO updateCarouselImageDTO) {
        return carouselImageService.updateCarouselImage(updateCarouselImageDTO);
    }
}

